﻿// ===================================
// The use and distribution terms for this software are covered by the Microsoft public license, 
// visit for more info : http://testcommander.codeplex.com 
// 
// You must not remove this copyright notice, or any other, from this software
// 
// Senthil Maruthaiappan  senips@gmail.com
// ===================================

using System.IO;
using System.Text;
using QAPro.Test.FitServices.Interfaces;
using QAPro.Test.Interfaces;
using WiseLight.Framework.Lite.Container;

namespace QAPro.Test.Addin.FitnesseUI
{
    public class TestReportDisplay : ITestReportWriter
    {
        private IFitUtilService _fitUtilService;
        private StringBuilder _resultHtml = new StringBuilder();

        private IFitUtilService FitUtilityService
        {
            get
            {
                if (_fitUtilService == null)
                    _fitUtilService = Services.Get<IFitUtilService>();
                return _fitUtilService;
            }
        }

        public IServices Services { get; set; }

        public ITestCase TestedItem { get; set; }

        public string ResultHtml
        {
            get { return _resultHtml.ToString(); }
        }

        #region ITestReportWriter Members

        public bool CanGenerateReport
        {
            get { return true; }
        }

        public void GenerateReport()
        {
            if (TestedItem != null)
            {
                _resultHtml = new StringBuilder();
                using (var writer = new StringWriter(_resultHtml))
                {
                    FitUtilityService.WriteHtmlResult(TestedItem, writer);
                }
            }
        }

        #endregion
    }
}